﻿/*========================================================================
打开新页面

========================================================================*/
function OpenWin(url) {
    var width = screen.availWidth - 10;
    var height = screen.availHeight - 25;
    option = "width=" + width + ",height=" + height + ",left=0,top=0,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes"
    window.open(url, "_blank", option);
}

function OpenWin_S(url, window_width, window_height) {
    var window_left = (screen.availWidth / 2) - (window_width / 2) - 25;
    var window_top = (screen.availHeight / 2) - (window_height / 2) - 25;
    var window_dimensions = "height=" + window_height +
                            ",width=" + window_width +
                            ",left=" + window_left +
                            ",top=" + window_top +
                            ",toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no"
    window.open(url, "", window_dimensions)
}

function OpenWin_M(url, name, window_width, window_height) {
    var window_left = (screen.availWidth / 2) - (window_width / 2) - 25;
    var window_top = (screen.availHeight / 2) - (window_height / 2) - 25;
    var window_dimensions = "height=" + window_height +
                            ",width=" + window_width +
                            ",left=" + window_left +
                            ",top=" + window_top +
                            ",toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
    window.open(url, name, window_dimensions)
}

/*========================================================================
弹出框脚本

=======================================================================*/
//弹出窗口
function ShowDialog(dialogPage, pageWidth, pageHeight) {
    var retval = "";
    retval = window.showModalDialog(dialogPage, null, "dialogWidth:" + pageWidth + "px;dialogHeight:" + pageHeight + "px;help:no;scroll:yes;status;no");
    if (retval == null || retval == "") {
        return "";
    }
}

//弹出窗口
function ShowMyDialogs(txtId, dialogPage, pageWidth, pageHeight) {
    var txt = document.getElementById(txtId);
    var retval = "";
    retval = window.showModalDialog(dialogPage, null, "dialogWidth:" + pageWidth + "px;dialogHeight:" + pageHeight + "px;help:no;scroll:yes;status;no");
    if (retval == null || retval == "") {
        return "";
    }
    txt.value = retval;
}


//返回多个数据
function ShowReturnArrarDialogs(texts, dialogPage, pageWidth, pageHeight) {
    var retval = "";
    var txt;
    retval = window.showModalDialog(dialogPage, null, "dialogWidth:" + pageWidth + "px;dialogHeight:" + pageHeight + "px;help:no;scroll:yes;status;no");

    if (retval == null || retval == "") {
        return "";
    }

    var arr = retval.split("§");
    var tArr = texts.split("§");
    //多个值返回到一个控件

    if (tArr.length == 1) {
        txt = document.getElementById(tArr);

        txt.value = unescape(arr);
    }

    if (arr.length != tArr.length) {
        return "";
    }
    //多个值返回到多个控件
    for (var i = 0; i < arr.length; i++) {
        txt = document.getElementById(tArr[i]);
        if (txt != null) {

            txt.value = unescape(arr[i]);
        }
    }

}


function ShowReturnManyArrarDialogs(txtIds, dialogPage, pageWidth, pageHeight) {
    var retval = "";
    retval = window.showModalDialog(dialogPage, null, "dialogWidth:" + pageWidth + "px;dialogHeight:" + pageHeight + "px;help:no;scroll:yes;status;no");
    //debugger;
    if (retval == null || retval == "") {
        return "";
    }
    var arr1 = retval.split("$");
    var arrId = txtIds.split("§");

    Clear(txtIds);
    for (var i = 0; i < arr1.length; i++) {

        var arr2 = arr1[i].split("§");

        if (arr2.length != arrId.length) {
            break;
        }

        for (var j = 0; j < arr2.length; j++) {
            document.getElementById(arrId[j]).value += arr2[j] + ",";
        }
    }

    for (var j = 0; j < arrId.length; j++) {
        var val = document.getElementById(arrId[j]).value;
        document.getElementById(arrId[j]).value = val.substring(0, val.length - 1);

    }
}

function ShowReturnManyNoticeDialogs(textId, valueId, dialogPage, pageWidth, pageHeight) {
    //    var retval = "";
    //    retval = window.showModalDialog(dialogPage, null, "dialogWidth:" + pageWidth + "px;dialogHeight:" + pageHeight + "px;help:no;scroll:yes;status;no");
    //    
    //    if (retval == null || retval == "") {
    //        return "";
    //    }
    //    document.getElementById(arrId[textId]).innerHTML="";
    //    document.getElementById(valueId).value="";
    //    var arr1 = retval.split("$");

    //    for (var i = 0; i < arr1.length; i++) {

    //            var arr2 = arr1[i].split("§");

    //            document.getElementById(arrId[textId]).innerHTML += arr2[0] + ",";
    //            document.getElementById(arrId[valueId]).value += arr2[1] + ",";
    //            
    //        }
    //    }

    //    for (var j = 0; j < arrId.length; j++) {
    //        var val = document.getElementById(valueId).value;
    //        document.getElementById(valueId).value = val.substring(0, val.length - 1);

    //    }
}


/*========================================================================
清除方法
========================================================================*/
function Clear(arrControls) {
    var tArr = arrControls.split("§");
    //清空所有控件值
    for (var i = 0; i < tArr.length; i++) {
        var txt = document.getElementById(tArr[i]);
        if (txt != null) {
            txt.value = "";
        }
    }
}